<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <form action="http://www.baidu.com">
        用户名：
        <input type="text" name="user" id="" minlength="6" maxlength="16" required pattern="^[a-z]+$" />
        <button type="submit">提交</button>
    </form>
    <script>
        var oForm = document.querySelector('form');
        var oInput = document.querySelector('input');

        // invalid 验证事件
        oInput.addEventListener('invalid', fn, true);

        function fn(ev) {
            console.log(ev);
            console.log(this.validity);

        }

        oForm.addEventListener('submit', function (ev) {
            ev.preventDefault();
        })
    </script>
</body>

</html>